package com.tao.plan.controller;

import com.tao.plan.common.R;
import com.tao.plan.common.exception.EmailBandingException;
import com.tao.plan.common.exception.LoginException;
import com.tao.plan.common.exception.TokenException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionController {
	@ExceptionHandler(EmailBandingException.class)
	public R emailBandingExceptionHandler(EmailBandingException e){
		log.error("验证码不正确: {}", e.getMsg());
		return R.build().fail(e.getCode(),e.getMsg());
	}
	@ExceptionHandler(LoginException.class)
	public R loginExceptionHandler(LoginException e){
		log.error("登录异常: {}", e.getMsg());
		return R.build().fail(e.getCode(),e.getMsg());
	}
	@ExceptionHandler(TokenException.class)
	public R tokenExceptionHandler(TokenException e){
		log.error("token异常: {}", e.getMsg());
		return R.build().fail(e.getCode(),e.getMsg());
	}
	@ExceptionHandler(Exception.class)
	public R exceptionHandler(Exception e){
		log.error("未知异常: {}", e.getMessage());
		return R.build().fail(e.getMessage());
	}
}
